Skip to content

Conversation

@adityachoudhari26
Copy link
Member

@adityachoudhari26 adityachoudhari26 commented Feb 10, 2026

Summary by CodeRabbit

  • New Features

    • Added conditional execution support for workflow jobs. Jobs can now include a condition expression that determines whether they should run, enabling more flexible and dynamic workflow configurations.
  • Tests

    • Added test coverage for conditional job execution to verify jobs are correctly skipped or executed based on their conditions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

Conditional job execution is added to workflows through a new CEL expression field ("if") in JobTemplate. This field is defined in schema specifications, propagated through code generation, and evaluated by the workflow manager at runtime to skip jobs when conditions are false.

Changes

Cohort / File(s) Summary
Schema Definitions
apps/workspace-engine/oapi/openapi.json, apps/workspace-engine/oapi/spec/schemas/workflows.jsonnet, packages/workspace-engine-sdk/src/schema.ts
Added optional CEL expression field "if" to WorkflowJobTemplate schema to enable conditional job execution.
Code Generation
apps/workspace-engine/pkg/oapi/oapi.gen.go
Generated Go struct updated with new If field (pointer to string) as part of WorkflowJobTemplate.
Workflow Manager Logic
apps/workspace-engine/pkg/workspace/workflowmanager/manager.go
Implements CEL evaluation logic with evaluateJobTemplateIf helper and package-scoped CEL environment. Jobs with false-evaluating conditions are skipped during workflow creation.
Manager Tests
apps/workspace-engine/pkg/workspace/workflowmanager/manager_test.go
Adds test case verifying conditional job skipping for workflows with true and false "if" expressions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit hops through workflows bright,
With CEL expressions shining light,
Some jobs run true, some skip with flair,
Conditions met, a dance so fair! ✨🐰

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for conditional triggering of workflow jobs via CEL expressions across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch conditional-job-trigger

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/workspace-engine/pkg/workspace/workflowmanager/manager.go`:
- Around line 16-18: The global initialization currently ignores errors from
celutil.NewEnvBuilder().WithMapVariable("inputs").BuildCached(...) so
workflowCelEnv can be nil and later cause a panic when calling Compile; change
the initialization to capture the returned (env, err), check err (and that env
!= nil) and fail fast or return an error from the surrounding init/constructor
(or log and os.Exit) so callers don't hit Compile on a nil env; update any code
that assumed the package-global (e.g., where Compile is invoked) to handle the
initialization error if you convert initialization to a function that returns
(env, error) instead of a silent global.
🧹 Nitpick comments (1)
apps/workspace-engine/pkg/workspace/workflowmanager/manager_test.go (1)

264-265: Consider asserting the identities of the created jobs, not just the count.

If a bug caused the wrong job to be skipped (e.g., true-job skipped instead of false-job), this test would still pass since it only checks Len(wfJobs, 2). Verifying the Ref or config of each created workflow job would catch that class of bug.

♻️ Suggested addition after the length assertion
 	wfJobs := store.WorkflowJobs.GetByWorkflowId(wf.Id)
 	assert.Len(t, wfJobs, 2, "should have 2 jobs: always-job and true-job, but not false-job")
+
+	jobRefs := make([]string, len(wfJobs))
+	for i, wj := range wfJobs {
+		jobRefs[i] = wj.Ref
+	}
+	assert.Contains(t, jobRefs, "test-job-agent", "always-job should be present")
+	assert.Contains(t, jobRefs, "test-job-agent", "true-job should be present")

Note: Since all three jobs share the same Ref, you'd need to check by a distinguishing field (e.g., the config or the workflow job's association back to the template job ID) for a truly robust assertion.

Comment on lines +16 to +18
var workflowCelEnv, _ = celutil.NewEnvBuilder().
WithMapVariable("inputs").
BuildCached(24 * time.Hour)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n apps/workspace-engine/pkg/workspace/workflowmanager/manager.go | head -100

Repository: ctrlplanedev/ctrlplane

Length of output: 3801


🏁 Script executed:

find apps/workspace-engine -name "celutil*" -type f

Repository: ctrlplanedev/ctrlplane

Length of output: 48


🏁 Script executed:

rg -l "celutil" apps/workspace-engine --type go | head -20

Repository: ctrlplanedev/ctrlplane

Length of output: 859


🏁 Script executed:

cat -n apps/workspace-engine/pkg/celutil/cel.go

Repository: ctrlplanedev/ctrlplane

Length of output: 8195


🏁 Script executed:

rg "workflowCelEnv" apps/workspace-engine/pkg/workspace/workflowmanager/manager.go

Repository: ctrlplanedev/ctrlplane

Length of output: 167


Handle CEL env initialization errors instead of ignoring them.

If BuildCached fails, workflowCelEnv is nil and calling Compile at line 63 will panic. Capture the error and surface it (or fail fast) before evaluation.

🔧 Suggested fix
-var workflowCelEnv, _ = celutil.NewEnvBuilder().
+var workflowCelEnv, workflowCelEnvErr = celutil.NewEnvBuilder().
 	WithMapVariable("inputs").
 	BuildCached(24 * time.Hour)
 func (m *Manager) evaluateJobTemplateIf(jobTemplate oapi.WorkflowJobTemplate, inputs map[string]any) (bool, error) {
+	if workflowCelEnvErr != nil {
+		return false, fmt.Errorf("failed to initialize workflow CEL environment: %w", workflowCelEnvErr)
+	}
 	prg, err := workflowCelEnv.Compile(*jobTemplate.If)
 	if err != nil {
 		return false, fmt.Errorf("failed to compile CEL expression for job %q: %w", jobTemplate.Name, err)
 	}
🤖 Prompt for AI Agents
In `@apps/workspace-engine/pkg/workspace/workflowmanager/manager.go` around lines
16 - 18, The global initialization currently ignores errors from
celutil.NewEnvBuilder().WithMapVariable("inputs").BuildCached(...) so
workflowCelEnv can be nil and later cause a panic when calling Compile; change
the initialization to capture the returned (env, err), check err (and that env
!= nil) and fail fast or return an error from the surrounding init/constructor
(or log and os.Exit) so callers don't hit Compile on a nil env; update any code
that assumed the package-global (e.g., where Compile is invoked) to handle the
initialization error if you convert initialization to a function that returns
(env, error) instead of a silent global.

@adityachoudhari26 adityachoudhari26 merged commit 40816ff into main Feb 10, 2026
10 of 12 checks passed
@adityachoudhari26 adityachoudhari26 deleted the conditional-job-trigger branch February 10, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants